---
title: "Spring Validator"
categories:
- java
- spring
tags:
---

<div id="content">
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org1a99668">Request Body Validator</a>
<ul>
<li><a href="#org8d72f52">Hibernate 处理国际化Message的类：</a></li>
</ul>
</li>
<li><a href="#orgbc28254">Request Param Validator</a></li>
</ul>
</div>
</div>
<div class="outline-2" id="outline-container-org1a99668">
<h2 id="org1a99668">Request Body Validator</h2>
<div class="outline-text-2" id="text-org1a99668">
<p>
RequestResponseBodyMethodProcessor#resolveArgument:
new MethodArgumentNotValidException(parameter, binder.getBindingResult());
</p>
<p>
然后通过 ExceptionAdvice 处理这个异常
</p>
</div>
<div class="outline-3" id="outline-container-org8d72f52">
<h3 id="org8d72f52">Hibernate 处理国际化Message的类：</h3>
<div class="outline-text-3" id="text-org8d72f52">
<p>
org/hibernate/validator/messageinterpolation/AbstractMessageInterpolator.java
</p>
</div>
</div>
</div>
<div class="outline-2" id="outline-container-orgbc28254">
<h2 id="orgbc28254">Request Param Validator</h2>
<div class="outline-text-2" id="text-orgbc28254">
<p>
抛出的是javax.validation.ConstraintViolationException异常
</p>
<pre class="example">
isValid:34, PasswordValidator (com.niimbot.app.cloud.general.validator)
isValid:13, PasswordValidator (com.niimbot.app.cloud.general.validator)
validateSingleConstraint:171, ConstraintTree (org.hibernate.validator.internal.engine.constraintvalidation)
validateConstraints:68, SimpleConstraintTree (org.hibernate.validator.internal.engine.constraintvalidation)
validateConstraints:73, ConstraintTree (org.hibernate.validator.internal.engine.constraintvalidation)
doValidateConstraint:127, MetaConstraint (org.hibernate.validator.internal.metadata.core)
validateConstraint:120, MetaConstraint (org.hibernate.validator.internal.metadata.core)
validateMetaConstraint:552, ValidatorImpl (org.hibernate.validator.internal.engine)
validateMetaConstraints:534, ValidatorImpl (org.hibernate.validator.internal.engine)
validateParametersForSingleGroup:997, ValidatorImpl (org.hibernate.validator.internal.engine)
validateParametersForGroup:938, ValidatorImpl (org.hibernate.validator.internal.engine)
validateParametersInContext:868, ValidatorImpl (org.hibernate.validator.internal.engine)
validateParameters:281, ValidatorImpl (org.hibernate.validator.internal.engine)
validateParameters:233, ValidatorImpl (org.hibernate.validator.internal.engine)
invoke:105, MethodValidationInterceptor (org.springframework.validation.beanvalidation)
proceed:186, ReflectiveMethodInvocation (org.springframework.aop.framework)
proceed:749, CglibAopProxy$CglibMethodInvocation (org.springframework.aop.framework)
intercept:691, CglibAopProxy$DynamicAdvisedInterceptor (org.springframework.aop.framework)
</pre>
</div>
</div>
</div>
<div class="status" id="postamble">
<p class="author">Author: gdme1320</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
